package com.yay.danceline.provider;


import com.yay.danceline.provider.DLDatabase.Tables;
import android.net.Uri;
import android.provider.BaseColumns;

/**
 * Get Started!
 * @author yakovlev.yuriy@gmail.com
 * @author Dmitry Makeev
 *
 * Contract class for interacting with {@link DLProvider}. Unless
 * otherwise noted, all time-based fields are milliseconds since epoch and can
 * be compared against {@link System#currentTimeMillis()}.
 * <p>
 * The backing {@link ContentProvider} assumes that {@link Uri} are generated
 * using stronger {@link String} identifiers, instead of {@code int}
 * {@link BaseColumns#_ID} values, which are prone to shuffle during sync.
 */
public class DLContract {
	
    public interface TracksColumns extends BaseColumns {
        /** Unique string identifying parent category. */
    	String IDP = "idp";
        /** Artist */
        String ARTIST = "artist";
        /** Name */
        String NAME = "name";
        /** URL */
        String URL = "url";
    }

    public static final String CONTENT_AUTHORITY = "com.yay.danceline";
    private static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
    private static final String PATH_TRACKS = "tracks";

    
    /**
     * Each recipe is a block that has instructions and ingredients
     */
    public static class Track implements TracksColumns, BaseColumns {
        public static final Uri CONTENT_URI =
                BASE_CONTENT_URI.buildUpon().appendPath(PATH_TRACKS).build();

        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.m5.tracks";
        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.m5.tracks";

        /** Default "ORDER BY" clause. */
        public static final String DEFAULT_SORT = Tables.TRACKS + "." + TracksColumns.NAME + " COLLATE NOCASE ASC";
        
        /** Build {@link Uri} for requested {@link #RECIPE_ID}. */
        public static Uri buildTracksUri(String categoryId) {
            return CONTENT_URI.buildUpon().appendPath(categoryId).build();
        }

        /** Read {@link #_ID} from {@link Recipe} {@link Uri}. */
        public static String getCategoryId(Uri uri) {
            if(uri!=null && uri.getPathSegments()!=null) {
            	return uri.getPathSegments().get(1);
            } else {
            	return null;
            }
        }

    }
    
    private DLContract() {
    }
}
